package Week2.J0424;

import java.util.Arrays;

public class 扑克牌顺子 {
    public boolean IsContinuous (int[] numbers) {
        Arrays.sort(numbers);
        int anyCard = 0;
        for (int i = 0; i < numbers.length; i++) {
            if (numbers[i] == 0) {
                anyCard++;
            }

            if (anyCard == 4) return true;

            if (i > 0 && numbers[i-1] != numbers[i]) {
                int cost = numbers[i] - numbers[i-1];
                anyCard -= cost;
                if (anyCard < 0) return false;
            }
        }
        return true;
    }
}
